package com.think.teaching.service.impl;

import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;

import javax.crypto.SecretKey;

import org.bouncycastle.jcajce.provider.symmetric.util.BaseSecretKeyFactory;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.think.teaching.mapper.ExpRateMapper;
import com.think.teaching.model.ExpRate;

@Service
public class ExpRateSeviceImpl extends BaseServiceImpl<ExpRateMapper,ExpRate> {

	public Boolean setExpRate(Integer expId, Integer userId, Integer rate) {
		QueryWrapper<ExpRate> queryWrapper = new QueryWrapper<ExpRate>();
		queryWrapper.eq("exp_id", expId).eq("user_id", userId);
		ExpRate expRate = getOne(queryWrapper);
		if (expRate == null) {
			expRate = new ExpRate();
			expRate.setExpId(expId);
			expRate.setUserId(userId);
		}
		expRate.setRate(rate);
		return saveOrUpdate(expRate);
	}
	
	public Float getAvgExpRate(Integer expId) {
		return baseMapper.getAvgRate(expId);
	}
}
